﻿#region Copyright

// /*
// SilverlightInEnterprise
// SilverlightInEnterprise.Common
// RibbonGroup.cs
// 
// Author: Matt Van Horn
// Created 11/15/2011 6:30 PM
// Copyright: Silverlight in the Enterprise www.slinenterprise.com
// 
// Licensed under MS-PL http://www.opensource.org/licenses/MS-PL and while you 
// may use this in anyway you see fit and owe us nothing to do so, we wouldn't mind knowing that you got value out of the work we did (so we will do more) so 
// we ask that you leave a comment on www.slinenterprise.com or on the codeplex site slinenterprise.codeplex.com
// 
// */

#endregion

using System.Linq;
using SilverlightInEnterprise.Interfaces.Ribbon;

namespace SilverlightInEnterprise.Common.Ribbon
{
    public class RibbonGroup : RibbonItem, IRibbonGroup
    {
        public RibbonGroup()
        {
        }

        protected override void PopulateChildren()
        {
            var potentialTools =
                this.Locator.CompositionProvider.GetExports<IRibbonTool, IRibbonToolExportMetadata>();
            var actualTools = from g in potentialTools
                              where
                                  g.Metadata.TabName == this.TabName &&
                                  g.Metadata.GroupName == this.DisplayName
                              select g;
            var tools = actualTools.OrderBy(g => g.Metadata.Index).Select(g => g.Value).ToList();
            foreach (var ribbonTool in tools)
            {
                this._Children.Add(ribbonTool);
            }
        }

        public string TabName { get; protected set; }
    }
}